#include <cstring>
#include <iterator>
#include <algorithm>
#include <iostream>
using namespace std;

//n: length of array
//m: positions to be rotated
//TIME = O(n);SPACE = O(n)
void rotate_left(int a[],int n, int m)
{
  m = m%n;

  int* tmp = (int*)malloc(m*sizeof(int));

  memcpy(tmp,a,m*sizeof(int));
  memmove(a,a+m,(n-m)*sizeof(int));
  memcpy(a+n-m,tmp,m*sizeof(int));

  free(tmp);
}

int main()
{
  int a[] = {0,1,2,3,4,5,6,7,8,9};
  copy(a,a+10,ostream_iterator<int>(cout," "));
  cout<<endl;
  rotate_left(a,10,13);
  copy(a,a+10,ostream_iterator<int>(cout," "));
  cout<<endl;

  return 0;
}
